Decomposition¶

Decomposition is the process of breaking a problem into smaller pieces.

Defining the boundaries, interface, and purpose of the smaller pieces is call abstraction.

Decomposition and abstraction go hand-in-hand and are essential skills in programming.

Treasure! 🧑🏻‍🎨¶

treasure.py¶

No description has been provided for this image

To reach the cave, Bit must follow these instructions:

  • Turn right on blue squares.
  • Turn left on red squares.

Once in the cave, navigate through the passage to the treasure (red square).

Paint the path followed green.

NOTES

Break the problem up into get-to-the-cave and find-the-treasure.

The flying has move, paint, and turn statements. What order is necessary?

  • the paint step can clobber the turn step.

Finding the treasure involves a nested if. It's essentially the same logic as scurry.py from lab 6.

Over the Mountain 🏔️¶

hike.py¶

No description has been provided for this image No description has been provided for this image

Bit needs to plant trees all over the mountain.

Paint only the squares directly above a blocked square.

NOTES

Look at both inputs to assess the requirements. Do we need a while loop for climbing, as opposed to a hard coded number of move statements? How do we know?

How do we break this problem up? What are the patterns that we see? Are there natural subproblems, like we had with treasure.py a moment ago?

Key Ideas¶

  • Break big problems into smaller problems
  • Purposefully define the boundaries of the pieces so it is clear how they fit back together